package com.linchong.concurrency.chapter6;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author:linchong
 * @CreateTime:2020-01-04 09:36
 * @Description:优雅的关闭线程，通过打断的方式
 */
@Slf4j
public class ThreadCloseGraceful2 {
	private static class Worker extends Thread {


		@Override
		public void run() {
			while (true) {
				if (Thread.interrupted()) {
					break;
				}
				//to do other jobs
			/*	try {
					Thread.sleep(1);
				} catch (InterruptedException e) {
					*//*return*//*
					 break;
				}*/
			}
			// break and
		}

	}

	public static void main(String[] args) {
		Worker worker = new Worker();
		worker.start();
		try {
			Thread.sleep(3_000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		worker.interrupt();
	}


}
